package com.server.llh.llhserverwork.activity.work;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.family.llh.lelaohuitoastview.dialog.toast.T;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lelaohui.net.listener.NetDataListener;
import com.lelaohui.net.netmanager.INetRequestManager;
import com.lelaohui.net.netmanager.ServerNetRequestManager;
import com.lelaohui.net.request.LRequest;
import com.lelaohui.net.utils.UrlsTools;
import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.activity.base.BaseFragment;
import com.server.llh.llhserverwork.activity.my.LoginActivity;
import com.server.llh.llhserverwork.activity.my.PayTaskActivity;
import com.server.llh.llhserverwork.activity.my.SignInActivity;
import com.server.llh.llhserverwork.bean.Constants;
import com.server.llh.llhserverwork.bean.SerTransField;
import com.server.llh.llhserverwork.bean.SerTransWapBean;
import com.server.llh.llhserverwork.utils.ServerPort;
import com.server.llh.llhserverwork.utils.SharedPreferenceUtil;
import com.server.llh.llhserverwork.utils.TimeUtils;
import com.server.llh.llhserverwork.utils.ToastTool;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by ZTF on 2017-06-27.
 */

public class SerTaskFragment extends BaseFragment {

    private static final String FRAGMENT_INDEX = "fragment_index";
    private final int FIRST_FRAGMENT = 0;
    private final int SECOND_FRAGMENT = 1;
    private final int THIRD_FRAGMENT = 2;
    private final int FOUR_FRAGMENT = 3;
    @BindView(R.id.startTime)
    TextView startTime;
    @BindView(R.id.stopTime)
    TextView stopTime;
    @BindView(R.id.queryServer)
    TextView queryServer;
    @BindView(R.id.timeView)
    LinearLayout timeView;
    @BindView(R.id.health_lv)
    ListView healthLv;
    SwipeRefreshLayout refrash_data;
    Unbinder unbinder;
    private int mCurIndex = -1;
    private static final String TAG = "SerOrderFragment";
    private List<SerTransField> fieldList = new ArrayList<SerTransField>();
    /**
     * 标志位，标志已经初始化完成
     */
    private boolean isPrepared;
    /**
     * 是否已被加载过一次，第二次就不再去请求数据了
     */
    private boolean mHasLoadedOnce;
    View rootView;
    String userId, orgId, orgType, userNameStr, workOrg, partTimeOrg, token;


    public static SerTaskFragment newInstance(int index) {
        Bundle bundle = new Bundle();
        bundle.putInt(FRAGMENT_INDEX, index);
        SerTaskFragment fragment = new SerTaskFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    Context context;
    Map<String, String> waiterOrgList = new HashMap<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        userId = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.USER_ID, this.getActivity().getApplicationContext());
        token = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.TOKEN_STR,
                getActivity().getApplicationContext());
        userNameStr = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.USER_NAMW,
                getActivity().getApplicationContext());
        orgId = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.ORG_ID,
                getActivity().getApplicationContext());
        orgType = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.ORG_TYPE,
                getActivity().getApplicationContext());
        if (LoginActivity.waiterOrgList != null) {
            waiterOrgList = LoginActivity.waiterOrgList;
            try {
                if (waiterOrgList.get("workOrg").toString() != null) {
                    workOrg = waiterOrgList.get("workOrg").toString();
                }
            } catch (Exception E) {
            }
            try {
                if (waiterOrgList.get("partTimeOrg").toString() != null) {
                    partTimeOrg = waiterOrgList.get("partTimeOrg").toString();
                }
            } catch (Exception E) {

            }

        }

        context = this.getActivity().getApplicationContext();
//        SignInActivity.registSignInAndOut(this);
        if (rootView == null) {
            rootView = super.onCreateView(inflater, container, savedInstanceState);
            unbinder = ButterKnife.bind(this, rootView);
            Bundle bundle = getArguments();
            if (bundle != null) {
                mCurIndex = bundle.getInt(FRAGMENT_INDEX);
            }
            isPrepared = true;
            lazyLoad();
        }
        refrash_data = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_container);
        refrash_data.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                onRefreshReq();
            }
        });
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (parent != null) {
            parent.removeView(rootView);
        }
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    private void onRefreshReq() {
        Log.d(TAG, "mHasLoadedOnce==" + mHasLoadedOnce + "isPrepared==" + isPrepared + "mHasLoadedOnce==" + mHasLoadedOnce);
        if (isPrepared == false || mHasLoadedOnce) {
            isPrepared = true;
            mHasLoadedOnce = false;
        }
        lazyLoad();
    }

//    @Override
//    public void onResume() {
//        onRefreshReq();
//        super.onResume();
//    }

    @Override
    protected void lazyLoad() {
        if (!isPrepared || !isVisible || mHasLoadedOnce) {
            Log.d(TAG, "isPrepared==" + isPrepared + "isVisible==" + isVisible + "mHasLoadedOnce==" + mHasLoadedOnce);
            return;
        }
        switch (mCurIndex) {
//            case FIRST_FRAGMENT:
//                reqServerTask(userId, FIRST_FRAGMENT + 1);
//                break;
            case SECOND_FRAGMENT:
                reqServerTask(userId, SECOND_FRAGMENT + 1);
                break;
            case THIRD_FRAGMENT:
                reqServerTask(userId, THIRD_FRAGMENT + 1);
                break;
            case FOUR_FRAGMENT:
                reqServerTask(userId, FOUR_FRAGMENT + 1);
                break;
        }
    }

    private void reqServerTask(String mUserId, int searchType) {
        try {
            LRequest lRequest = new LRequest();
//            lRequest.addParam("waiterId", mUserId);
            lRequest.addParam("searchType", searchType);
            lRequest.addParam("supplierId", orgId);
            Log.d(TAG, "searchType2222==" + searchType + "waiterId2222==" + mUserId);
            lRequest.setUri(ServerPort.SEARCH_SER_TASK_JSON);
            lRequest.setUriType(UrlsTools.SERVER_TASK_REQ);
            lRequest.setIp(UrlsTools.SERVER_REQ_URL);
            lRequest.setType(String.class);
            requestData(lRequest, new NetDataListener<String>() {
                @Override
                public void onError(Throwable t) {
                    try {
                        if (refrash_data != null) {
                            refrash_data.setRefreshing(false);
                        }
                        T.showAnimErrorToast(SerTaskFragment.this.getActivity(), "请求超时！");
                    } catch (Exception e) {
                    }
                }

                @Override
                public void onNext(String responseBean, String code) {
                    try{
                        if (refrash_data != null) {
                            refrash_data.setRefreshing(false);
                        }
                    }catch (Exception e){

                    }
                    Log.d(TAG, "responseBean2222==" + responseBean.toString());
                    switch (mCurIndex) {
                        case FIRST_FRAGMENT:
                            Log.d(TAG, "responseBean333==" + responseBean.toString());
                            setData(responseBean);
                            break;
                        case SECOND_FRAGMENT:
                            setData(responseBean);
                            break;
                        case THIRD_FRAGMENT:
                            setData(responseBean);
                            break;
                        case FOUR_FRAGMENT:
                            setData(responseBean);
                            break;
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void setData(String responseBean) {
        try {
            if (responseBean != null) {
                mHasLoadedOnce = true;
                listData.clear();
                Log.d(TAG, "searchType2222==" + mHasLoadedOnce + "waiterId2222==" + mHasLoadedOnce);
                Log.d(TAG, "responseBean==" + responseBean);
                listData = new Gson().fromJson(responseBean,
                        new TypeToken<List<SerTransWapBean>>() {
                        }.getType());
                adapter = new HealthTaskAdapter(getActivity().getApplicationContext(), listData);
                healthLv.setAdapter(adapter);
                adapter.notifyDataSetChanged();
            } else {
                mHasLoadedOnce = true;
            }
        } catch (Exception E) {

        }

    }


    HealthTaskAdapter adapter = null;
    List<SerTransWapBean> listData = new ArrayList<>();
//
//    @Override
//    public void callBack(String succ, String transStatus, String packDetailId, String serTransId, String customerId, String serSignRecordId,String isHasField) {
//        Log.d(TAG, "succ==" + succ + "transStatus==" + transStatus + "packDetailId==" + packDetailId + "serTransId==" + serTransId +
//                "customerId==" + customerId+"isHasField=="+isHasField);
//        try {
//            if ("5".equals(transStatus) || "10".equals(transStatus) || "2".equals(transStatus)
//                    || "4".equals(transStatus)) {
////                uploadReSendValue(serTransId, "12", customerId, packDetailId, Integer.valueOf(succ), serSignRecordId);
//            } else if ("12".equals(transStatus)&&"1".equals(isHasField)) {
//                if (SignInActivity.fieldLists!=null){
////                    uploadReSendValue2(serTransId, "6", customerId, packDetailId, Integer.valueOf(succ), serSignRecordId,SignInActivity.fieldLists);
//
//                }
//            } else if ("12".equals(transStatus)) {
////                uploadReSendValue(serTransId, "6", customerId, packDetailId, Integer.valueOf(succ), serSignRecordId);
//            }
//        } catch ( Exception e) {
//            e.printStackTrace();
//        }
//
//    }
//
//    @Override
//    public void refreshData(String code) {
//
//
//    }

    public class HealthTaskAdapter extends BaseAdapter {

        private int mLastVisibility;
        private int mLastPosition;
        private View mLastView;
        List<SerTransWapBean> listData;

        public List<SerTransWapBean> getListData() {
            return listData;
        }

        public void setListData(List<SerTransWapBean> listData) {
            this.listData = listData;
        }

        private Context context;

        public HealthTaskAdapter(Context context, List<SerTransWapBean> listData) {
            this.listData = listData;
            this.context = context;
            mLastPosition = -1;
        }

        @Override
        public int getCount() {
            return listData == null ? 0 : listData.size();
        }

        @Override
        public Object getItem(int arg0) {
            return listData == null ? null : listData.get(arg0);
        }

        @Override
        public long getItemId(int arg0) {
            return arg0;
        }

        @Override
        public View getView(final int position, View convertView,
                            ViewGroup parent) {
            ViewHolder holder = new ViewHolder();
            if (convertView == null) {
                convertView = LayoutInflater.from(context).inflate(
                        R.layout.subscribe_item_view, null);
                holder.server_name = (TextView) convertView
                        .findViewById(R.id.client_name);
                holder.client_age = (TextView) convertView
                        .findViewById(R.id.client_age);
                holder.server_time = (TextView) convertView
                        .findViewById(R.id.server_time);
                holder.order_time = (TextView) convertView
                        .findViewById(R.id.order_time);
                holder.client_num = (TextView) convertView
                        .findViewById(R.id.client_num);
                holder.client_server = (TextView) convertView
                        .findViewById(R.id.client_server);
                holder.subscribe_server_order = (TextView) convertView
                        .findViewById(R.id.subscribe_server_order);
                holder.subscribe_Revoke = (TextView) convertView
                        .findViewById(R.id.subscribe_Revoke);
                holder.client_address = (TextView) convertView
                        .findViewById(R.id.client_address);
                holder.content_view = (ListView) convertView
                        .findViewById(R.id.content_view);
                holder.textcreate = (TextView) convertView
                        .findViewById(R.id.textcreate);
                holder.server_remark = (TextView) convertView
                        .findViewById(R.id.server_remark);
                holder.ll_value = (LinearLayout) convertView
                        .findViewById(R.id.ll_value);
                HealthValueAdapter otherAdapter = new HealthValueAdapter();
                holder.content_view.setAdapter(otherAdapter);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            final SerTransWapBean taskBean = listData.get(position);
            taskBean.setPosition(position);
            HealthValueAdapter otherAdapter = null;
            if (holder.content_view.getAdapter() != null) {
                otherAdapter = (HealthValueAdapter) holder.content_view
                        .getAdapter();
            } else {
                otherAdapter = new HealthValueAdapter();
            }
            otherAdapter.setSerTransField(taskBean.getFieldList());
            otherAdapter.notifyDataSetChanged();

            if ("5".equals(taskBean.getTransStatus()) || "10".equals(taskBean.getTransStatus()) || "2".equals(taskBean.getTransStatus())
                    || "4".equals(taskBean.getTransStatus())) {
                holder.subscribe_server_order.setText("签到执行");
            } else if (taskBean.getTransStatus() != null && "12".equals(taskBean.getTransStatus()) && taskBean.getIsHasField() != null && taskBean.getIsHasField() == 1) {
                holder.subscribe_server_order.setText("执行任务");
            } else if (taskBean.getTransStatus() != null && "12".equals(taskBean.getTransStatus()) && taskBean.getIsHasField() != null && taskBean.getIsHasField() == 0) {
                holder.subscribe_server_order.setText("签退完成");
            } else if (taskBean.getTransStatus() != null && "6".equals(taskBean.getTransStatus())) {
                holder.subscribe_server_order.setVisibility(View.GONE);
            }
            holder.subscribe_server_order
                    .setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Long a = taskBean.getSubCateId();
                            if (taskBean.getIsHasField() == null) {
                                taskBean.setIsHasField(0);
                            }
                            int isHasField = taskBean.getIsHasField();

                            if (taskBean.getIsHasField() != null && isHasField == 1) {
                                if ("5".equals(taskBean.getTransStatus()) || "10".equals(taskBean.getTransStatus()) || "2".equals(taskBean.getTransStatus())
                                        || "4".equals(taskBean.getTransStatus())) {
                                    ToastTool.showText(
                                            getActivity().getApplicationContext(),
                                            "请签到,谢谢");
                                    goSignInt(context, taskBean.getCustomerId(), taskBean.getCustomerName(), taskBean.getTransStatus(), taskBean.getPackDetailId() + "", taskBean.getSerTransId() + "", position, taskBean.getSerSignRecordId(), "" + taskBean.getIsHasField(), null);
                                    return;
                                }
                                View view = (View) v.getParent()
                                        .getParent();
                                changeImageVisable(view,
                                        taskBean.getPosition());
                            } else {
                                if ("5".equals(taskBean.getTransStatus()) || "10".equals(taskBean.getTransStatus()) || "2".equals(taskBean.getTransStatus())
                                        || "4".equals(taskBean.getTransStatus())) {
                                    ToastTool.showText(
                                            getActivity().getApplicationContext(),
                                            "请签到,谢谢");
                                    goSignInt(context, taskBean.getCustomerId(), taskBean.getCustomerName(), taskBean.getTransStatus(), taskBean.getPackDetailId() + "", taskBean.getSerTransId() + "", position, taskBean.getSerSignRecordId(), "" + taskBean.getIsHasField(), null);
                                    return;
                                } else if ("12".equals(taskBean.getTransStatus()) && isHasField == 0) {
                                    ToastTool.showText(
                                            getActivity().getApplicationContext(),
                                            "请签退,谢谢");
                                    goSignInt(context, taskBean.getCustomerId(), taskBean.getCustomerName(), taskBean.getTransStatus(), taskBean.getPackDetailId() + "", taskBean.getSerTransId() + "", position, taskBean.getSerSignRecordId(), "" + taskBean.getIsHasField(), null);
                                    return;
                                } else if (taskBean.getSubCateId() != null && a == 1) {
                                    Intent intent = new Intent(getActivity().getApplicationContext(), PayTaskActivity.class);
                                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                    intent.putExtra("serTransId",
                                            taskBean.getSerTransId() + "");
                                    intent.putExtra("transStatus",
                                            taskBean.getTransStatus() + "");
                                    intent.putExtra("subCateId",
                                            taskBean.getSubCateId() + "");
                                    intent.putExtra("customerId",
                                            taskBean.getCustomerId() + "");
                                    intent.putExtra("supplierTypeId",
                                            taskBean.getSupplierTypeId());
                                    intent.putExtra("supplierId",
                                            taskBean.getSupplierId());
                                    startActivity(intent);
                                }
                            }
                        }
                    });


            holder.order_time.setText(TimeUtils.dateToString(taskBean
                    .getAddTime()));
            holder.server_name.setText(taskBean.getCustomerName());
            holder.client_age.setText("");
            if (taskBean.getCustomerAddress() != null) {
                holder.client_server.setText("地址:" + taskBean.getCustomerAddress());
            } else {
                holder.client_server.setText("地址: 无");
            }
            holder.server_remark.setText("备注：" + taskBean.getRemark());
            if (taskBean.getServiceName() != null) {
                holder.client_address.setText("" + taskBean.getServiceName());
            } else {
                holder.client_address.setText("备注：" +"无");
            }
            if (taskBean.getCustomerPhone() != null) {
                holder.client_num.setText(taskBean.getCustomerPhone());
            } else {
                holder.client_num.setText("");
            }
            String startTime = TimeUtils.dateToString(taskBean
                    .getSerStartTime());
            String endTimeStr = TimeUtils
                    .dateToString(taskBean.getSerEndTime());
            holder.server_time.setText(startTime.substring(5,
                    startTime.length() - 3)
                    + "--" + endTimeStr.substring(5, endTimeStr.length() - 3));

            holder.textcreate.setTag(holder.content_view);
            holder.textcreate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ListView listView = (ListView) v.getTag();
                    View temp = null;
                    StringBuffer sb = new StringBuffer();
                    SerTransField data = null;
                    StringBuffer fieldId = new StringBuffer();
                    StringBuffer fieldName = new StringBuffer();
                    ArrayList<Integer> prositonList = new ArrayList<Integer>();
                    for (int i = 0; i < listView.getChildCount(); i++) {
                        SerTransField transField = new SerTransField();
                        transField.setSerTransFieldId(taskBean.getFieldList()
                                .get(i).getSerTransFieldId());
                        temp = listView.getChildAt(i).findViewById(
                                R.id.et_values);
                        if (temp != null) {
                            EditText ed = (EditText) temp;
                            data = (SerTransField) temp.getTag();
                            prositonList.add(data.getPosition());
                            sb.append(ed.getText().toString()).append(",");
                            fieldId.append(data.getFieldId()).append(",");
                            fieldName.append(data.getFieldName()).append(",");
                            transField.setFieldValue(ed.getText().toString());
                            ed.setText("");
                        }
                        if (temp.getClass() == RelativeLayout.class) {
                            temp = temp.findViewById(R.id.et_values);
                        }
                        fieldList.add(transField);

                    }
                    ToastTool.showText(
                            getActivity().getApplicationContext(),
                            "请签退提交,谢谢");
                    goSignInt(context, taskBean.getCustomerId(), taskBean.getCustomerName(), taskBean.getTransStatus(), taskBean.getPackDetailId() + "", taskBean.getSerTransId() + "", position, taskBean.getSerSignRecordId(), taskBean.getIsHasField() + "", fieldList);
                }
            });

            if (mLastPosition == position) {
                holder.ll_value.setVisibility(mLastVisibility);
            } else {
                holder.ll_value.setVisibility(View.GONE);
            }

            return convertView;
        }

        public void changeImageVisable(View view, int position) {
            if (mLastView != null && mLastPosition != position) {
                ViewHolder holder = (ViewHolder) mLastView.getTag();
                switch (holder.ll_value.getVisibility()) {
                    case View.VISIBLE:
                        holder.ll_value.setVisibility(View.GONE);
                        mLastVisibility = View.GONE;
                        notifyDataSetChanged();
                        HealthValueAdapter otherAdapter = new HealthValueAdapter();
                        otherAdapter.notifyDataSetChanged();
                        break;
                }
            }
            mLastPosition = position;
            mLastView = view;
            ViewHolder holder = (ViewHolder) view.getTag();
            switch (holder.ll_value.getVisibility()) {
                case View.GONE:
                    holder.ll_value.setVisibility(View.VISIBLE);
                    mLastVisibility = View.VISIBLE;
                    notifyDataSetChanged();
                    HealthValueAdapter otherAdapter = new HealthValueAdapter();
                    otherAdapter.notifyDataSetChanged();
                    break;
                case View.VISIBLE:
                    holder.ll_value.setVisibility(View.GONE);
                    mLastVisibility = View.GONE;
                    notifyDataSetChanged();
                    HealthValueAdapter otherAdapter1 = new HealthValueAdapter();
                    otherAdapter1.notifyDataSetChanged();
                    break;
            }
        }

        class ViewHolder {
            TextView te_name, server_name, server_time, server_finish, order_time,
                    client_server, client_age, client_address, client_num,
                    subscribe_Revoke, subscribe_server_order, server_remark, textcreate,
                    client_server_time, unitName;
            ImageView llh_image;
            ListView content_view;
            LinearLayout ll_value;

            EditText te_values;
        }

        class HealthValueAdapter extends BaseAdapter {
            List<SerTransField> serTransField;

            public List<SerTransField> getSerTransField() {
                return serTransField;
            }

            public void setSerTransField(List<SerTransField> serTransField) {
                this.serTransField = serTransField;
            }

            public HealthValueAdapter() {
            }

            HealthValueAdapter(List<SerTransField> serTransField) {
                this.serTransField = serTransField;
            }

            @Override
            public int getCount() {
                if (serTransField == null || serTransField.size() == 0) {
                    return 0;
                }
                return serTransField.size();
            }

            @Override
            public Object getItem(int position) {
                return position;
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {

                if (convertView == null) {
                    ViewHolder h1 = new ViewHolder();
                    convertView = LayoutInflater.from(context).inflate(
                            R.layout.additem, null);
                    h1.te_name = (TextView) convertView
                            .findViewById(R.id.textname);
                    h1.te_values = (EditText) convertView
                            .findViewById(R.id.et_values);
                    h1.unitName = (TextView) convertView
                            .findViewById(R.id.unitName);
                    convertView.setTag(h1);
                }
                ViewHolder h = (ViewHolder) convertView.getTag();
                SerTransField serTranValue = serTransField.get(position);
                h.te_name.setText(serTranValue.getFieldName());
                h.te_values.setText(serTranValue.getFieldValue() == null ? ""
                        : serTranValue.getFieldValue());
                h.te_values.setTag(serTranValue);
                h.unitName.setText(serTranValue.getFieldUnit());
                return convertView;
            }
        }
    }

    private void uploadReSendValue(String serTransId, String transStatus, String customerId,
                                   String packDetailId,
                                   final int position, String serSignRecordId) throws JSONException {
        try {
            LRequest lRequest = new LRequest();
            lRequest.addParam("waitersName", URLEncoder.encode(userNameStr, "UTF-8"));
            lRequest.addParam("waitersId", userId);
            lRequest.addParam("serTransId", serTransId);
            lRequest.addParam("customerId", customerId);
            lRequest.addParam("transStatus", transStatus);
            lRequest.addParam("token", token);
            if (partTimeOrg != null) {
                lRequest.addParam("partTimeOrg", partTimeOrg);
            }
            if (workOrg != null) {
                lRequest.addParam("workOrg", workOrg);
            }
            if (serSignRecordId != null) {
                lRequest.addParam("serSignRecordId", serSignRecordId);
            }
            lRequest.addParam("packDetailId", packDetailId);
            lRequest.setUri(ServerPort.UPDATE_AUTOMA_TASK_JSON);
            lRequest.setUriType(UrlsTools.SERVER_TASK_REQ);
            lRequest.setType(String.class);
            requestData(lRequest, new NetDataListener<String>() {
                @Override
                public void onError(Throwable t) {
                    try {
                        T.showAnimErrorToast(getActivity().getApplicationContext(), "请求超时!");
                    } catch (Exception E) {

                    }
                }

                @Override
                public void onNext(String responseBean, String code) {
                    if (responseBean != null) {
                        listData.clear();
                        if (adapter != null) {
                            adapter.notifyDataSetChanged();
                        }
                        Log.d(TAG, "responseBean===" + responseBean + "code11==" + code);
                        if (isPrepared || mHasLoadedOnce) {
                            isPrepared = true;
                            mHasLoadedOnce = false;
                            isVisible = true;
                        }
                        lazyLoad();
                    }
                }
            });
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }


    private void uploadReSendValue2(String serTransId, String transStatus, String customerId,
                                    String packDetailId,
                                    final int position, String serSignRecordId, List<SerTransField> fieldList) throws JSONException {
        try {
            JSONObject json = new JSONObject();
            json.put("isHasField", 1);
            JSONArray jsArray = new JSONArray();
            json.put("fieldList", jsArray);
            for (int i = 0; i < fieldList.size(); i++) {
                JSONObject fieldJson = new JSONObject();
                fieldJson.put("serTransFieldId", fieldList.get(i)
                        .getSerTransFieldId());
                fieldJson.put("fieldValue", fieldList.get(i).getFieldValue());
                jsArray.put(fieldJson);
            }

            LRequest lRequest = new LRequest();
            lRequest.addParam("waitersName", URLEncoder.encode(userNameStr, "UTF-8"));
            lRequest.addParam("waitersId", userId);
            lRequest.addParam("serTransId", serTransId);
            lRequest.addParam("customerId", customerId);
            lRequest.addParam("transStatus", transStatus);
            lRequest.addParam("token", token);

            if (json != null) {
                Log.d(TAG, "json.toString()==" + json.toString());
                lRequest.addParam("fieldList", json.toString());
            }
            lRequest.addParam("transStatus", transStatus);
            if (partTimeOrg != null) {
                lRequest.addParam("partTimeOrg", partTimeOrg);
            }
            if (workOrg != null) {
                lRequest.addParam("workOrg", workOrg);
            }
            if (serSignRecordId != null) {
                lRequest.addParam("serSignRecordId", serSignRecordId);
            }
            lRequest.addParam("packDetailId", packDetailId);
            lRequest.setUri(ServerPort.UPDATE_AUTOMA_TASK_JSON);
            lRequest.setUriType(UrlsTools.SERVER_TASK_REQ);
            lRequest.setType(String.class);
            requestData(lRequest, new NetDataListener<String>() {
                @Override
                public void onError(Throwable t) {
                    try {
                        T.showAnimErrorToast(getActivity().getApplicationContext(), "请求超时!");
                    } catch (Exception E) {

                    }
                }

                @Override
                public void onNext(String responseBean, String code) {
                    if (responseBean != null) {
                        listData.clear();
                        if (adapter != null) {
                            adapter.notifyDataSetChanged();
                        }
                        Log.d(TAG, "responseBean===" + responseBean + "code22==" + code);
                        if (mHasLoadedOnce == true || isPrepared == false || isVisible) {
                            isVisible = true;
                            isPrepared = true;
                            mHasLoadedOnce = false;
                        }
                        lazyLoad();
                    }
                }
            });
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }


    @Override
    public void showProgress() {
        try {
            showProgress(this.getActivity().getApplicationContext());
            if (refrash_data != null) {
                refrash_data.setRefreshing(true);
            }
        } catch (Exception e) {

        }

    }

    @Override
    public void hideProgress() {
        try {
            closeProgress();
            if (refrash_data != null) {
                refrash_data.setRefreshing(false);
            }
        } catch (Exception e) {

        }
    }

    @Override
    protected INetRequestManager getRequestManager() {
        return ServerNetRequestManager.getInstance();
    }

    @Override
    public int getLayoutView() {
        return R.layout.activity_health_task;
    }

    @Override
    public void initView(View view) {

    }

    @Override
    public void doBases() {

    }

    public static List<SerTransField> fieldLists = new ArrayList<>();

    public void goSignInt(Context context, String customerId, String customerName, String transStatus,
                          String packDetailId, String serTransId,
                          int position, String serSignRecordId, String isHasField, List<SerTransField> fieldList
    ) {
        Intent intent = new Intent(context, SignInActivity.class);
        intent.putExtra("customerId", customerId);
        intent.putExtra("customerName", customerName);
        intent.putExtra("transStatus", transStatus);
        intent.putExtra("packDetailId", packDetailId);
        intent.putExtra("serTransId", serTransId);
        intent.putExtra("isHasField", isHasField);
        intent.putExtra("position", position + "");
        if (serSignRecordId != null) {
            intent.putExtra("serSignRecordId", serSignRecordId);
        }
        if (fieldList != null) {
            this.fieldLists = fieldList;
        }
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

}
